package tq.com.systools.system;

import android.text.Editable;
import android.widget.EditText;

import java.util.ArrayList;
import java.util.List;

public class StringHelper {
    public static boolean isEmpty(String s){
        return (s == null || s.length() == 0);
    }
    public static boolean hasText(EditText pEditText){
        Editable lEditable = pEditText.getText();
        if(lEditable == null) return false;

        String string = lEditable.toString();
        return !isEmpty(string);
    }

    public static String editText(EditText pEditText){
        Editable lEditable = pEditText.getText();
        if(lEditable == null) return "";

        String string = lEditable.toString();
        return string;
    }

    /** * 纯数字
     * @param str
     * @return */
    public static boolean isNumeric(String str){
        if(str == null || str.length() == 0) return false;

        for (int i = str.length();--i>=0;){
            if (!Character.isDigit(str.charAt(i))){
                return false;
            }
        }
        return true;
    }

    public static String join(List<String> pStrings, String split){
        if(pStrings == null || pStrings.size() == 0) return "";

        StringBuffer lBuffer = new StringBuffer();
        for (String s:
             pStrings) {
            if(lBuffer.length() > 0){
                lBuffer.append(split);
            }
            lBuffer.append(s);
        }

        return lBuffer.toString();
    }


    static public ArrayList<String> splite(String string, String split){
        if(string == null || string.length() == 0) return null;

        String[] items = string.split(split);
        ArrayList<String> lStrings = new ArrayList<>();
        for (String s:
             items) {
            if(s == null || s.length() == 0){
                continue;
            }
            lStrings.add(s);
        }
        return lStrings;
    }

}
